<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<img src="images/8-4-继承实现.jpg" style="width: 500px"/>
<script>
    /*
         0.原型链
     */
    function SuperType() {
        this.property = true;
    }

    SuperType.prototype.getSuperValue = function () {
        return this.property;
    };

    function SubType() {
        this.subproperty = false;
    }

    // 继承SuperType
    SubType.prototype = new SuperType();
    SubType.prototype.getSubValue = function () {
        return this.subproperty;
    };
    let instance = new SubType();
    console.log(instance)
    console.log(instance.getSuperValue()); // true

    /*
        4.原型链问题
     */
    function SuperType4() {
        this.colors = ["red", "blue", "green"];
    }

    function SubType4() {
    }

    // 继承SuperType
    SubType4.prototype = new SuperType4();
    let instance1 = new SubType4();
    instance1.colors.push("black");
    console.log(instance1.colors); // "red,blue,green,black"
    let instance2 = new SubType4();
    console.log(instance2.colors); // "red,blue,green,black"

</script>
</body>
</html>